package com.example.demo.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.user.entity.UWithdrawal;
import com.example.demo.user.entity.UWithdrawal;
import com.example.demo.user.service.UWithdrawalService;
import com.example.demo.user.service.UWithdrawalService;
import com.example.demo.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 金额提现记录表; 前端控制器
 * </p>
 *
 * @author 涛
 * @since 2024-08-01
 */
@RestController
@RequestMapping("/uWithdrawal")
@Tag(name = "uWithdrawal", description = "用户金额提现记录表")
public class UWithdrawalController {
    @Autowired
    private UWithdrawalService uWithdrawalService;

    /**
     * 获取用户金额提现记录模块列表
     */
    @GetMapping("/getUWithdrawalList")
    @Operation(summary = "获取用户金额提现记录列表接口", description = "获取用户金额提现记录列表接口")
    public Result<?> getUWithdrawalList(@RequestParam(value = "current", required = false, defaultValue = "1")Integer current,
                                    @RequestParam(value = "size", required = false, defaultValue = "10")Integer size,
                                    UWithdrawal uWithdrawal){
        Page<UWithdrawal> page = new Page<>(current,size);
        QueryWrapper<UWithdrawal> queryWrapper = new QueryWrapper<>(uWithdrawal);
        return Result.ok(uWithdrawalService.page(page,queryWrapper));
    }

    /**
     * 根据ID查询用户金额提现记录
     */
    @GetMapping("/getUWithdrawalById")
    @Operation(summary = "根据id查询用户金额提现记录明细", description = "根据id查询用户金额提现记录明细")
    public Result<?> getUWithdrawalById(Integer id){
        return Result.ok(uWithdrawalService.getById(id));
    }

    /**
     * 修改用户金额提现记录
     */
    @PutMapping("/updateUWithdrawal")
    @Operation(summary = "根据id修改用户金额提现记录明细", description = "根据id修改用户金额提现记录明细")
    @Transactional
    public Result<?> updateUWithdrawal(@RequestBody UWithdrawal uWithdrawal){
        return Result.ok(uWithdrawalService.updateById(uWithdrawal));
    }

    /**
     * 新增用户金额提现记录
     */
    @PostMapping("/addUWithdrawal")
    @Operation(summary = "新增用户金额提现记录明细", description = "新增用户金额提现记录明细")
    public Result<?> addUWithdrawal(@RequestBody UWithdrawal uWithdrawal){
        return Result.ok(uWithdrawalService.save(uWithdrawal));
    }

    /**
     * 删除用户金额提现记录
     */
    @DeleteMapping("/deleteUWithdrawalById")
    @Operation(summary = "删除用户金额提现记录", description = "删除用户金额提现记录")
    @Transactional
    public Result<?> deleteUWithdrawalById(Integer id){
        return Result.ok(uWithdrawalService.removeById(id));
    }
}